<template>
	<view>
		<u-navbar placeholder fixed autoBack title="搜索"></u-navbar>
		<view class="search u-border-bottom d-p-l-30 d-p-r-30 d-p-t-20 d-p-b-20 d-flex">
			<view class="input d-flex d-flex-1">
				<u-icon name="search" size="38rpx" color="#ADB4BD"></u-icon>
				<view class="d-flex-1"><u--input v-model="keyWord" border="none" style="padding: 0;height: 75rpx;" placeholder="请输入姓名或证件号码进行查询"></u--input></view>
			</view>
			<u-button @click="search()" text="搜索" type="primary" :customStyle="{ width: '136rpx', height: '75rpx', marginLeft: '20rpx' }"></u-button>
		</view>
		<u-gap height="115rpx" bgColor="#ffffff"></u-gap>
		<view class="d-p-30">
			<view class="d-font-28">
				<view class="d-flex" v-for="(item, index) in list" :key="index" style="height: 100rpx;" @click="memberDetail(item)">
					<view class="u-line-1" style="width: 160rpx;">{{ item.xm }}</view>
					<view class="d-flex-1" style="font-weight: bold;">{{ item.zjhm }}</view>
					<view style="margin-right: 104rpx;"><u--image width="32rpx" height="32rpx" src="/static/icon/icon-53.png"></u--image></view>
					<u--image width="19rpx" height="32rpx" src="/static/icon/icon-52.png"></u--image>
				</view>

				<template v-if="!list || list.length <= 0">
					<view style="padding-top: 20vh;"><u-empty icon="/static/image/none.png" :text="!show ? '请输入关键词进行搜索' : '未搜索到数据'"></u-empty></view>
				</template>
			</view>
		</view>
	</view>
</template>

<script>
import { cpgMember } from '../../../common/api.js';
export default {
	data() {
		return {
			pageNum: 1,
			pageSize: 20,
			pageLast: 1,
			list: [],
			keyWord: '',
			show: false
		};
	},
	onReachBottom() {
		if (this.pageNum < this.pageLast) {
			++this.pageNum;
			this.cpgMember().then(e => {
				this.list = this.list.concat(e.data);
			});
		}
	},
	methods: {
		search() {
			if (!this.keyWord) {
				return uni.$u.toast('请输入关键词再进行搜索');
			}
			this.show = false;
			this.init();
		},
		init() {
			uni.showLoading({
				title: '搜索中...',
				mask: true
			});
			this.pageNum = 1;
			this.list = [];
			this.cpgMember().then(e => {
				this.list = e.data;
				this.pageLast = Math.ceil(e.total / this.pageSize);
				this.show = true;
				uni.hideLoading();
			});
		},
		cpgMember() {
			return cpgMember({
				params: {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					id: this.$user.ssgcxx[this.$appIndex].bzid,
					keyWord: this.keyWord
				}
			});
		},
		memberDetail(item) {
			uni.$u.route({
				url: '/pages/index/member/memberDetail',
				params: {
					id: item.id
				}
			});
		}
	}
};
</script>

<style lang="scss">
.search {
	position: fixed;
	left: 0;
	right: 0;
	z-index: 999;
	background-color: #ffffff;
	.input {
		height: 75rpx;
		background: #f6f7f8;
		border-radius: 10rpx;
		padding: 0 20rpx;
	}
}
</style>
